#include <cstring>
#include <iostream>
#include <list>
#include <string>
//
// Created by lingzhitech on 25-9-24.
//
int main() {
    {
        // 使用std::string的== operator
        std::list<std::string> roster1 = {"ab", "b", "c", "d", "e", "f", "ab"};
        std::list<std::string> roster2 = {"ab", "b", "c", "d", "e", "f", "ab"};
        bool isSame = equal(roster1.cbegin(), roster1.cend(), roster2.cbegin());
        std::cout << "The same " << isSame << std::endl;
    } {
        //字符串字面量通常存储在只读静态存储区，相同的字面量值可能有相同的地址，所以比较的时候通常也会相同
        std::list<const char *> roster1 = {"ab", "b", "c", "d", "e", "f",};
        std::list<const char *> roster2 = {"ab", "b", "c", "d", "e", "f",};
        bool isSame = equal(roster1.cbegin(), roster1.cend(), roster2.cbegin());
        std::cout << "The same " << isSame << std::endl;
    } {
        //正确的比较const char*的思路
        std::list<const char *> roster1 = {"abc", "b", "c", "d", "e", "f",};
        std::list<const char *> roster2 = {"abc", "b", "c", "d", "e", "f",};
        bool isSame = equal(roster1.cbegin(), roster1.cend(), roster2.cbegin(),
                            [](const char *a, const char *b) { return strcmp(a, b) == 0; });
        std::cout << "The same " << isSame << std::endl;
    }
}